/// <reference types="vitest"/>
import { PluginOption, defineConfig, splitVendorChunkPlugin } from 'vite';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';

// https://vitejs.dev/config/
export default defineConfig({
  // 确保你的配置项是正确的类型
  plugins: [
    react(),
    splitVendorChunkPlugin(),
    visualizer({
      open: true,
      gzipSize: true,
      brotliSize: true,
      filename: 'stats.html',
    }) as PluginOption,
  ],
  build: {
    minify: true,
    target: 'esnext',
    rollupOptions: {
      output: {
        manualChunks(id: string) {
          if (id.includes('antd')) {
            return 'and-chunk';
          }
        },
      },
    },
  },
  server: {
    proxy: {
      // '/api': {
      //   target: 'http://localhost:3001/api',
      //   changeOrigin: true,
      // },
      '/api': 'http://localhost:3001',
    },
  },
  test: {
    environment: 'jsdom',
  },
});
